namespace OneWorks.Utils.FluentData
{
    using System;
    using System.Linq;

    internal class DataReaderField
    {
        public int Index { get; private set; }
        public string LowerName { get; private set; }
        public string Name { get; private set; }
        public Type Type { get; private set; }
        private readonly string[] _nestedPropertyNames;
        private readonly int _nestedLevels;

        public DataReaderField(int index, string name, Type type)
        {
            this.Index = index;
            this.Name = name;
            this.LowerName = name.ToLower();
            this.Type = type;
            this._nestedPropertyNames = this.LowerName.Split('_');
            this._nestedLevels = this._nestedPropertyNames.Count() - 1;
        }

        public string GetNestedName(int level)
        {
            return this._nestedPropertyNames[level];
        }

        public int NestedLevels
        {
            get
            {
                return this._nestedLevels;
            }
        }

        public bool IsSystem
        {
            get
            {
                return this.Name.IndexOf("FLUENTDATA_") > -1;
            }
        }
    }
}